import pandas as pd
import uuid
import json
import time
import mysql.connector
import tos
import logging
from bytehouse_driver import Client
import numpy as np


def add_to_bytehouse_dict(dict):
    HOST = "bytehouse-cn-beijing.volces.com"
    PORT = "19000"
    API_KEY = "q2p9nLj7tq:TKOCmgrMKp"
    # 配置数据库连接信息
    DATABASE = "dwd"
    client = Client.from_url(
        'bytehouse://{}:{}/?user=bytehouse&password={}&database={}&secure=true'.format(HOST, PORT, API_KEY,
                                                                                       DATABASE))
    start_time_str = dict['scid_start_time_str']
    hour = start_time_str[11:13]

    client.execute("INSERT INTO dwd.dwd_trigger_sc_ep40_tda4_v4 VALUES", [
        [dict['vehicle_id'], dict['start_time_str'], dict['scid'], dict['path'], dict['level1'], dict['level2'],
         dict['level3'], dict['day'], dict['month'], dict["scid_start_time_str"], dict['icu2_odometer'],
         dict['idb3_vehiclespd'],dict['acu2_longaccsensorvalue'], dict['acu2_lataccsensorvalue'], dict['acu2_vehicledynyawrate'],
         dict['eps1_steeranglespd'],dict["lane_curvature"], dict['eps1_torsionbartorque'], dict['cs1_gearpositionreqst'], dict['uid'],
         dict['day']]])
def get_model_emergency_steering(df_100ms_save_path, vechicle_id, daystr, hourstr, bagid, uuids, file_type, dtc,sc):
    try:
        df_100ms = pd.read_pickle(df_100ms_save_path)
        print(df_100ms.columns)
    except Exception as e:
        print('data report read error, ', str(e))
    df_100ms_list = df_100ms[
        ['start_time_str', 'path', 'nsecs', 'VLCCDHypotheses_Hypothesis_0_fTTC', 'VLCCDHypotheses_Hypothesis_0_fDistX',
         'VLCCDHypotheses_Hypothesis_0_fDistY',
         'VLCCDHypotheses_Hypothesis_0_fVrelX', 'VLCCDHypotheses_Hypothesis_0_fVrelY', 'IDB3_VehicleSpd',
         'ACU2_LongAccSensorValue', 'ACU2_LatAccSensorValue',
         'ACU2_VehicleDynYawRate', 'IDB1_BrakePedalApplied', 'EPS1_SteerAngleSpd',
         'CamLaneData_CourseInfo_1_CourseInfoSegNear_f_C0',
         'ADCS2_AEBPartialBrake', 'ADCS2_AEBFullBrake','ICU2_Odometer','EPS1_TorsionBarTorque','CS1_GearPositionReqSt','ADCS8_NNPSysState',
         'ADCS8_NPilot_SysState','ADCS2_EPS_LDPState','BDCS1_TurnLightSW'
         ]].values.tolist()
    found_index = -9999
    start_time_str=""
    found_ICU2_Odometer=0.0
    found_IDB3_VehicleSpd=0.0
    found_lane_curvature=0.0
    found_ACU2_LongAccSensorValue=0.0
    found_ACU2_LatAccSensorValue=0.0
    found_ACU2_VehicleDynYawRate=0.0
    found_EPS1_SteerAngleSpd=0.0
    found_EPS1_TorsionBarTorque=0.0
    found_CS1_GearPositionReqSt=0.0
    # 遍历列表
    for index, element in enumerate(df_100ms_list):
        start_time_str=element[0]
        path = element[1]
        nsecs = element[2]
        ADCS2_AEBPartialBrake = element[15]
        ADCS2_AEBFullBrake = element[16]
        ICU2_Odometer= element[17]
        IDB3_VehicleSpd = element[8]
        ACU2_LongAccSensorValue = element[9]
        ACU2_LatAccSensorValue = element[10]
        ACU2_VehicleDynYawRate = element[11]
        EPS1_SteerAngleSpd = element[13]
        lane_curvature = element[14]
        EPS1_TorsionBarTorque=element[18]
        CS1_GearPositionReqSt = element[19]
        ADCS8_NNPSysState = element[20]
        ADCS8_NPilot_SysState = element[21]
        ADCS2_EPS_LDPState= element[22]
        BDCS1_TurnLightSW = element[23]

        if (ADCS8_NNPSysState == 2 or ADCS8_NPilot_SysState == 2 or ADCS2_EPS_LDPState == 2) and (
                abs(ACU2_VehicleDynYawRate) > 2) and (BDCS1_TurnLightSW == 0) and \
                ((IDB3_VehicleSpd >= 100 and abs(EPS1_SteerAngleSpd) > 16) or \
                 (IDB3_VehicleSpd >= 80 and IDB3_VehicleSpd < 100 and abs(EPS1_SteerAngleSpd) > 22) or \
                 (IDB3_VehicleSpd >= 60 and IDB3_VehicleSpd < 80 and abs(EPS1_SteerAngleSpd) > 25) or \
                 (IDB3_VehicleSpd >= 50 and IDB3_VehicleSpd < 60 and abs(EPS1_SteerAngleSpd) > 40) or \
                 (IDB3_VehicleSpd >= 40 and IDB3_VehicleSpd < 50 and abs(EPS1_SteerAngleSpd) > 50) or \
                 (IDB3_VehicleSpd > 30 and IDB3_VehicleSpd < 40 and abs(EPS1_SteerAngleSpd) > 60)
                ):
            found_index = index
            found_ICU2_Odometer=ICU2_Odometer
            found_IDB3_VehicleSpd = IDB3_VehicleSpd
            found_ACU2_LongAccSensorValue =ACU2_LongAccSensorValue
            found_ACU2_LatAccSensorValue = ACU2_LatAccSensorValue
            found_ACU2_VehicleDynYawRate = ACU2_VehicleDynYawRate
            found_EPS1_SteerAngleSpd =EPS1_SteerAngleSpd
            found_EPS1_TorsionBarTorque =EPS1_TorsionBarTorque
            found_CS1_GearPositionReqSt =CS1_GearPositionReqSt
            found_lane_curvature=lane_curvature
            break  # 找到第一个符合条件的元素就跳出循环
    logging.info("found_index: "+str(found_index))
    df=get_model_feature(found_index, df_100ms_list, start_time_str)

    df_std = sc.transform(df)
    y_pred = dtc.predict(df_std)
    logging.info("预测结果： " + str(y_pred))
    # 输出值为2代表已碰撞，1代表危险但未碰撞，0代表不危险
    if y_pred[0] == 2:
        level1 = "已碰撞"
    elif y_pred[0] == 1:
        level1 = "危险但未碰撞"
    elif y_pred[0] == 0:
        level1 = "不危险"
    dict = {}
    dict["vehicle_id"] = vechicle_id
    dict["start_time_str"] = start_time_str
    dict["scid"] = bagid
    dict["path"] = path
    level2 = ""
    level3 = ""
    dict["level1"] = level1
    dict["level2"] = level2
    dict["level3"] = level3
    day = start_time_str[0:4] + start_time_str[5:7] + start_time_str[8:10]
    month = start_time_str[0:4] + start_time_str[5:7]
    dict["day"] = day
    dict["month"] = month
    dict["scid_start_time_str"] = start_time_str
    dict["icu2_odometer"] = found_ICU2_Odometer
    dict["idb3_vehiclespd"] = found_IDB3_VehicleSpd
    dict["acu2_longaccsensorvalue"] = found_ACU2_LongAccSensorValue
    dict["acu2_lataccsensorvalue"] = found_ACU2_LatAccSensorValue
    dict["acu2_vehicledynyawrate"] = found_ACU2_VehicleDynYawRate
    dict["eps1_steeranglespd"] = found_EPS1_SteerAngleSpd
    dict["lane_curvature"] = found_lane_curvature
    dict["eps1_torsionbartorque"] = found_EPS1_TorsionBarTorque
    dict["cs1_gearpositionreqst"] = found_CS1_GearPositionReqSt

    uid_string = vechicle_id + start_time_str + bagid + level1 + level2 + level3
    uid = str(uuid.uuid3(uuid.NAMESPACE_DNS, uid_string))
    dict["uid"] = uid

    add_to_bytehouse_dict(dict)
def get_model_feature(found_index,df_list,start_time_str):
    if found_index >= 11:
        VLCCDHypotheses_Hypothesis_0_fTTC_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fTTC_last= [row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_last_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_last)
        AEB_Target_Estimated_Time_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fTTC_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fTTC_next =[row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_next_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_next)
        AEB_Target_Estimated_Time_post = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistX_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistX_last= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_last)
        AEB_Target_Longitudinal_Distance_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp)


        VLCCDHypotheses_Hypothesis_0_fDistX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistX_next= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_next)
        AEB_Target_Longitudinal_Distance_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistY_last = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_last)
        AEB_Target_Cross_Range_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistY_next = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_next)
        AEB_Target_Cross_Range_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_last)
        AEB_Target_Longitudinal_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_next)
        AEB_Target_Longitudinal_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_last)
        AEB_Target_Lateral_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_next)
        AEB_Target_Lateral_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp)

        IDB3_VehicleSpd_last_list = df_list[found_index - 11:found_index - 1]
        IDB3_VehicleSpd_last = [row[8] for row in IDB3_VehicleSpd_last_list]
        IDB3_VehicleSpd_last_nnp = np.array(IDB3_VehicleSpd_last)
        IDB3_VehicleSpd_pre = np.mean(IDB3_VehicleSpd_last_nnp)

        IDB3_VehicleSpd_last_next_list = df_list[found_index + 1:found_index + 11]
        IDB3_VehicleSpd_last_next = [row[8] for row in IDB3_VehicleSpd_last_next_list]
        IDB3_VehicleSpd_last_next_nnp = np.array(IDB3_VehicleSpd_last_next)
        IDB3_VehicleSpd_post = np.mean(IDB3_VehicleSpd_last_next_nnp)

        ACU2_LongAccSensorValue_last_list = df_list[found_index - 11:found_index - 1]
        ACU2_LongAccSensorValue_last = [row[9] for row in ACU2_LongAccSensorValue_last_list]
        ACU2_LongAccSensorValue_last_nnp = np.array(ACU2_LongAccSensorValue_last)
        ACU2_LongAccSensorValue_pre = np.mean(ACU2_LongAccSensorValue_last_nnp)

        ACU2_LongAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LongAccSensorValue_next = [row[9] for row in ACU2_LongAccSensorValue_next_list]
        ACU2_LongAccSensorValue_next_nnp = np.array(ACU2_LongAccSensorValue_next)
        ACU2_LongAccSensorValue_post = np.mean(ACU2_LongAccSensorValue_next_nnp)

        ACU2_LatAccSensorValue_last_list = df_list[found_index - 11:found_index - 1]
        ACU2_LatAccSensorValue_last = [row[10] for row in ACU2_LatAccSensorValue_last_list]
        ACU2_LatAccSensorValue_last_nnp = np.array(ACU2_LatAccSensorValue_last)
        ACU2_LatAccSensorValue_pre = np.mean(ACU2_LatAccSensorValue_last_nnp)

        ACU2_LatAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LatAccSensorValue_next = [row[10] for row in ACU2_LatAccSensorValue_next_list]
        ACU2_LatAccSensorValue_next_nnp = np.array(ACU2_LatAccSensorValue_next)
        ACU2_LatAccSensorValue_post = np.mean(ACU2_LatAccSensorValue_next_nnp)

        ACU2_VehicleDynYawRate_last_list = df_list[found_index - 11:found_index - 1]
        ACU2_VehicleDynYawRate_last = [row[11] for row in ACU2_VehicleDynYawRate_last_list]
        ACU2_VehicleDynYawRate_last_nnp = np.array(ACU2_VehicleDynYawRate_last)
        ACU2_VehicleDynYawRate_pre = np.mean(ACU2_VehicleDynYawRate_last_nnp)

        ACU2_VehicleDynYawRate_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_VehicleDynYawRate_next = [row[11] for row in ACU2_VehicleDynYawRate_next_list]
        ACU2_VehicleDynYawRate_next_nnp = np.array(ACU2_VehicleDynYawRate_next)
        ACU2_VehicleDynYawRate_post = np.mean(ACU2_VehicleDynYawRate_next_nnp)

        AEB_Target_Estimated_Time_diff = AEB_Target_Estimated_Time_post - AEB_Target_Estimated_Time_pre
        AEB_Target_Longitudinal_Distance_diff = AEB_Target_Longitudinal_Distance_post - AEB_Target_Longitudinal_Distance_pre
        AEB_Target_Cross_Range_diff = AEB_Target_Cross_Range_post - AEB_Target_Cross_Range_pre
        AEB_Target_Longitudinal_Velocity_diff = AEB_Target_Longitudinal_Velocity_post - AEB_Target_Longitudinal_Velocity_pre
        AEB_Target_Lateral_Velocity_diff = AEB_Target_Lateral_Velocity_post - AEB_Target_Lateral_Velocity_pre
        IDB3_VehicleSpd_diff = IDB3_VehicleSpd_post - IDB3_VehicleSpd_pre
        ACU2_LongAccSensorValue_diff = ACU2_LongAccSensorValue_post - ACU2_LongAccSensorValue_pre
        ACU2_LatAccSensorValue_diff = ACU2_LatAccSensorValue_post - ACU2_LatAccSensorValue_pre
        ACU2_VehicleDynYawRate_diff = ACU2_VehicleDynYawRate_post - ACU2_VehicleDynYawRate_pre

        IDB1_BrakePedalApplied_next_list = df_list[found_index + 1:found_index + 11]
        IDB1_BrakePedalApplied_next = [row[12] for row in IDB1_BrakePedalApplied_next_list]
        IDB1_BrakePedalApplied_next_nnp = np.array(IDB1_BrakePedalApplied_next)
        IDB1_BrakePedalApplied = np.mean(IDB1_BrakePedalApplied_next_nnp)

        EPS1_SteerAngleSpd_next_list = df_list[found_index + 1:found_index + 11]
        EPS1_SteerAngleSpd_next = [row[13] for row in EPS1_SteerAngleSpd_next_list]
        EPS1_SteerAngleSpd_next_nnp = np.array(EPS1_SteerAngleSpd_next)
        EPS1_SteerAngleSpd = np.max(EPS1_SteerAngleSpd_next_nnp)

        lane_curve_list = []
        if found_index - 31 >= 0:
            lane_curve_list_fat = df_list[found_index - 31:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        else:
            lane_curve_list_fat = df_list[0:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        lane_curve = max(map(abs, lane_curve_list))
        logging.info("lane_curve: "+str(lane_curve))

        hour = start_time_str[11:13]
        data = {'AEB_Target_Estimated_Time_pre': [AEB_Target_Estimated_Time_pre],
                'AEB_Target_Estimated_Time_post': [AEB_Target_Estimated_Time_post],
                'AEB_Target_Longitudinal_Distance_pre': [AEB_Target_Longitudinal_Distance_pre],
                'AEB_Target_Longitudinal_Distance_post': [AEB_Target_Longitudinal_Distance_post],
                'AEB_Target_Cross_Range_pre': [AEB_Target_Cross_Range_pre],
                'AEB_Target_Cross_Range_post': [AEB_Target_Cross_Range_post],
                'AEB_Target_Longitudinal_Velocity_pre': [AEB_Target_Longitudinal_Velocity_pre],
                'AEB_Target_Longitudinal_Velocity_post': [AEB_Target_Longitudinal_Velocity_post],
                'AEB_Target_Lateral_Velocity_pre': [AEB_Target_Lateral_Velocity_pre],
                'AEB_Target_Lateral_Velocity_post': [AEB_Target_Lateral_Velocity_post],
                'IDB3_VehicleSpd_pre': [IDB3_VehicleSpd_pre],
                'IDB3_VehicleSpd_post': [IDB3_VehicleSpd_post],
                'ACU2_LongAccSensorValue_pre': [ACU2_LongAccSensorValue_pre],
                'ACU2_LongAccSensorValue_post': [ACU2_LongAccSensorValue_post],
                'ACU2_LatAccSensorValue_pre': [ACU2_LatAccSensorValue_pre],
                'ACU2_LatAccSensorValue_post': [ACU2_LatAccSensorValue_post],
                'ACU2_VehicleDynYawRate_pre': [ACU2_VehicleDynYawRate_pre],
                'ACU2_VehicleDynYawRate_post': [ACU2_VehicleDynYawRate_post],
                'AEB_Target_Estimated_Time_diff': [AEB_Target_Estimated_Time_diff],
                'AEB_Target_Longitudinal_Distance_diff': [AEB_Target_Longitudinal_Distance_diff],
                'AEB_Target_Cross_Range_diff': [AEB_Target_Cross_Range_diff],
                'AEB_Target_Longitudinal_Velocity_diff': [AEB_Target_Longitudinal_Velocity_diff],
                'AEB_Target_Lateral_Velocity_diff': [AEB_Target_Lateral_Velocity_diff],
                'IDB3_VehicleSpd_diff': [IDB3_VehicleSpd_diff],
                'ACU2_LongAccSensorValue_diff': [ACU2_LongAccSensorValue_diff],
                'ACU2_LatAccSensorValue_diff': [ACU2_LatAccSensorValue_diff],
                'ACU2_VehicleDynYawRate_diff': [ACU2_VehicleDynYawRate_diff],
                'IDB1_BrakePedalApplied': [IDB1_BrakePedalApplied],
                'EPS1_SteerAngleSpd': [EPS1_SteerAngleSpd],
                'lane_curve': [lane_curve],
                'hour': [hour]
                }
        df = pd.DataFrame(data)
    else:
        VLCCDHypotheses_Hypothesis_0_fTTC_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fTTC_last= [row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_last_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_last)
        AEB_Target_Estimated_Time_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fTTC_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fTTC_next =[row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_next_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_next)
        AEB_Target_Estimated_Time_post = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistX_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistX_last= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_last)
        AEB_Target_Longitudinal_Distance_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp)


        VLCCDHypotheses_Hypothesis_0_fDistX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistX_next= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_next)
        AEB_Target_Longitudinal_Distance_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistY_last = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_last)
        AEB_Target_Cross_Range_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistY_next = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_next)
        AEB_Target_Cross_Range_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_last)
        AEB_Target_Longitudinal_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_next)
        AEB_Target_Longitudinal_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_last)
        AEB_Target_Lateral_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_next)
        AEB_Target_Lateral_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp)

        IDB3_VehicleSpd_last_list = df_list[0:found_index - 1]
        IDB3_VehicleSpd_last = [row[8] for row in IDB3_VehicleSpd_last_list]
        IDB3_VehicleSpd_last_nnp = np.array(IDB3_VehicleSpd_last)
        IDB3_VehicleSpd_pre = np.mean(IDB3_VehicleSpd_last_nnp)

        IDB3_VehicleSpd_last_next_list = df_list[found_index + 1:found_index + 11]
        IDB3_VehicleSpd_last_next = [row[8] for row in IDB3_VehicleSpd_last_next_list]
        IDB3_VehicleSpd_last_next_nnp = np.array(IDB3_VehicleSpd_last_next)
        IDB3_VehicleSpd_post = np.mean(IDB3_VehicleSpd_last_next_nnp)

        ACU2_LongAccSensorValue_last_list = df_list[0:found_index - 1]
        ACU2_LongAccSensorValue_last = [row[9] for row in ACU2_LongAccSensorValue_last_list]
        ACU2_LongAccSensorValue_last_nnp = np.array(ACU2_LongAccSensorValue_last)
        ACU2_LongAccSensorValue_pre = np.mean(ACU2_LongAccSensorValue_last_nnp)

        ACU2_LongAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LongAccSensorValue_next = [row[9] for row in ACU2_LongAccSensorValue_next_list]
        ACU2_LongAccSensorValue_next_nnp = np.array(ACU2_LongAccSensorValue_next)
        ACU2_LongAccSensorValue_post = np.mean(ACU2_LongAccSensorValue_next_nnp)

        ACU2_LatAccSensorValue_last_list = df_list[0:found_index - 1]
        ACU2_LatAccSensorValue_last = [row[10] for row in ACU2_LatAccSensorValue_last_list]
        ACU2_LatAccSensorValue_last_nnp = np.array(ACU2_LatAccSensorValue_last)
        ACU2_LatAccSensorValue_pre = np.mean(ACU2_LatAccSensorValue_last_nnp)

        ACU2_LatAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LatAccSensorValue_next = [row[10] for row in ACU2_LatAccSensorValue_next_list]
        ACU2_LatAccSensorValue_next_nnp = np.array(ACU2_LatAccSensorValue_next)
        ACU2_LatAccSensorValue_post = np.mean(ACU2_LatAccSensorValue_next_nnp)

        ACU2_VehicleDynYawRate_last_list = df_list[0:found_index - 1]
        ACU2_VehicleDynYawRate_last = [row[11] for row in ACU2_VehicleDynYawRate_last_list]
        ACU2_VehicleDynYawRate_last_nnp = np.array(ACU2_VehicleDynYawRate_last)
        ACU2_VehicleDynYawRate_pre = np.mean(ACU2_VehicleDynYawRate_last_nnp)

        ACU2_VehicleDynYawRate_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_VehicleDynYawRate_next = [row[11] for row in ACU2_VehicleDynYawRate_next_list]
        ACU2_VehicleDynYawRate_next_nnp = np.array(ACU2_VehicleDynYawRate_next)
        ACU2_VehicleDynYawRate_post = np.mean(ACU2_VehicleDynYawRate_next_nnp)

        AEB_Target_Estimated_Time_diff = AEB_Target_Estimated_Time_post - AEB_Target_Estimated_Time_pre
        AEB_Target_Longitudinal_Distance_diff = AEB_Target_Longitudinal_Distance_post - AEB_Target_Longitudinal_Distance_pre
        AEB_Target_Cross_Range_diff = AEB_Target_Cross_Range_post - AEB_Target_Cross_Range_pre
        AEB_Target_Longitudinal_Velocity_diff = AEB_Target_Longitudinal_Velocity_post - AEB_Target_Longitudinal_Velocity_pre
        AEB_Target_Lateral_Velocity_diff = AEB_Target_Lateral_Velocity_post - AEB_Target_Lateral_Velocity_pre
        IDB3_VehicleSpd_diff = IDB3_VehicleSpd_post - IDB3_VehicleSpd_pre
        ACU2_LongAccSensorValue_diff = ACU2_LongAccSensorValue_post - ACU2_LongAccSensorValue_pre
        ACU2_LatAccSensorValue_diff = ACU2_LatAccSensorValue_post - ACU2_LatAccSensorValue_pre
        ACU2_VehicleDynYawRate_diff = ACU2_VehicleDynYawRate_post - ACU2_VehicleDynYawRate_pre

        IDB1_BrakePedalApplied_next_list = df_list[found_index + 1:found_index + 11]
        IDB1_BrakePedalApplied_next = [row[12] for row in IDB1_BrakePedalApplied_next_list]
        IDB1_BrakePedalApplied_next_nnp = np.array(IDB1_BrakePedalApplied_next)
        IDB1_BrakePedalApplied = np.mean(IDB1_BrakePedalApplied_next_nnp)

        EPS1_SteerAngleSpd_next_list = df_list[found_index + 1:found_index + 11]
        EPS1_SteerAngleSpd_next = [row[13] for row in EPS1_SteerAngleSpd_next_list]
        EPS1_SteerAngleSpd_next_nnp = np.array(EPS1_SteerAngleSpd_next)
        EPS1_SteerAngleSpd = np.max(EPS1_SteerAngleSpd_next_nnp)

        lane_curve_list = []
        if found_index - 31 >= 0:
            lane_curve_list_fat = df_list[found_index - 31:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        else:
            lane_curve_list_fat = df_list[0:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        lane_curve = max(map(abs, lane_curve_list))
        logging.info("lane_curve: "+str(lane_curve))

        hour = start_time_str[11:13]
        data = {'AEB_Target_Estimated_Time_pre': [AEB_Target_Estimated_Time_pre],
                'AEB_Target_Estimated_Time_post': [AEB_Target_Estimated_Time_post],
                'AEB_Target_Longitudinal_Distance_pre': [AEB_Target_Longitudinal_Distance_pre],
                'AEB_Target_Longitudinal_Distance_post': [AEB_Target_Longitudinal_Distance_post],
                'AEB_Target_Cross_Range_pre': [AEB_Target_Cross_Range_pre],
                'AEB_Target_Cross_Range_post': [AEB_Target_Cross_Range_post],
                'AEB_Target_Longitudinal_Velocity_pre': [AEB_Target_Longitudinal_Velocity_pre],
                'AEB_Target_Longitudinal_Velocity_post': [AEB_Target_Longitudinal_Velocity_post],
                'AEB_Target_Lateral_Velocity_pre': [AEB_Target_Lateral_Velocity_pre],
                'AEB_Target_Lateral_Velocity_post': [AEB_Target_Lateral_Velocity_post],
                'IDB3_VehicleSpd_pre': [IDB3_VehicleSpd_pre],
                'IDB3_VehicleSpd_post': [IDB3_VehicleSpd_post],
                'ACU2_LongAccSensorValue_pre': [ACU2_LongAccSensorValue_pre],
                'ACU2_LongAccSensorValue_post': [ACU2_LongAccSensorValue_post],
                'ACU2_LatAccSensorValue_pre': [ACU2_LatAccSensorValue_pre],
                'ACU2_LatAccSensorValue_post': [ACU2_LatAccSensorValue_post],
                'ACU2_VehicleDynYawRate_pre': [ACU2_VehicleDynYawRate_pre],
                'ACU2_VehicleDynYawRate_post': [ACU2_VehicleDynYawRate_post],
                'AEB_Target_Estimated_Time_diff': [AEB_Target_Estimated_Time_diff],
                'AEB_Target_Longitudinal_Distance_diff': [AEB_Target_Longitudinal_Distance_diff],
                'AEB_Target_Cross_Range_diff': [AEB_Target_Cross_Range_diff],
                'AEB_Target_Longitudinal_Velocity_diff': [AEB_Target_Longitudinal_Velocity_diff],
                'AEB_Target_Lateral_Velocity_diff': [AEB_Target_Lateral_Velocity_diff],
                'IDB3_VehicleSpd_diff': [IDB3_VehicleSpd_diff],
                'ACU2_LongAccSensorValue_diff': [ACU2_LongAccSensorValue_diff],
                'ACU2_LatAccSensorValue_diff': [ACU2_LatAccSensorValue_diff],
                'ACU2_VehicleDynYawRate_diff': [ACU2_VehicleDynYawRate_diff],
                'IDB1_BrakePedalApplied': [IDB1_BrakePedalApplied],
                'EPS1_SteerAngleSpd': [EPS1_SteerAngleSpd],
                'lane_curve': [lane_curve],
                'hour': [hour]
                }
        df = pd.DataFrame(data)
    return df
def add_to_bytehouse(dict_list):

    print(dict_list)
    HOST="bytehouse-cn-beijing.volces.com"
    PORT="19000"
    API_KEY="q2p9nLj7tq:TKOCmgrMKp"
    # 配置数据库连接信息
    DATABASE="dwd"
    client = Client.from_url('bytehouse://{}:{}/?user=bytehouse&password={}&database={}&secure=true'.format(HOST, PORT, API_KEY, DATABASE))
    client.execute("INSERT INTO dwd.dwd_trigger_sc_ep40_tda4_v4 VALUES", dict_list)
def get_ttc(df_can_20ms_list,df_can_100ms_list,found_index,found_nsecs,vechicle_id,bagid,scid_dict,dict_list):
    list_data = get_can_20ms_list(df_can_20ms_list, found_nsecs)
    VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID = list_data[2]
    EnvmGenObjectList_aObject_0_Kinematic_fDistX = list_data[5]
    EnvmGenObjectList_aObject_0_Kinematic_fVabsX = list_data[7]
    EnvmGenObjectList_aObject_1_Kinematic_fDistX = list_data[11]
    EnvmGenObjectList_aObject_1_Kinematic_fVabsX = list_data[13]
    EnvmGenObjectList_aObject_2_Kinematic_fDistX = list_data[17]
    EnvmGenObjectList_aObject_2_Kinematic_fVabsX = list_data[19]
    EnvmGenObjectList_aObject_3_Kinematic_fDistX = list_data[23]
    EnvmGenObjectList_aObject_3_Kinematic_fVabsX = list_data[25]
    EnvmGenObjectList_aObject_4_Kinematic_fDistX = list_data[29]
    EnvmGenObjectList_aObject_4_Kinematic_fVabsX = list_data[31]
    EnvmGenObjectList_aObject_5_Kinematic_fDistX = list_data[35]
    EnvmGenObjectList_aObject_5_Kinematic_fVabsX = list_data[37]

    start_time_str = df_can_100ms_list[found_index][0]
    path = df_can_100ms_list[found_index][1]
    IDB3_VehicleSpd = df_can_100ms_list[found_index][8]
    AccDisplayObj_CONTROL_ACCEL = df_can_100ms_list[found_index][24]

    if VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 0:
        ttc = EnvmGenObjectList_aObject_0_Kinematic_fDistX / (
                EnvmGenObjectList_aObject_0_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
        IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
        if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
            (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                (IDB3_VehicleSpd_flag > 10 and ttc < 2):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标ttc过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        gap = EnvmGenObjectList_aObject_0_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
        if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or ( IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
             (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标time_gap过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 1:
        ttc = EnvmGenObjectList_aObject_1_Kinematic_fDistX / (
                EnvmGenObjectList_aObject_1_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
        IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
        if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
            (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
            (IDB3_VehicleSpd_flag > 10 and ttc < 2):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标ttc过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
        gap = EnvmGenObjectList_aObject_1_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
        if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
            (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标time_gap过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 2:
        ttc = EnvmGenObjectList_aObject_2_Kinematic_fDistX / (
                EnvmGenObjectList_aObject_2_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
        IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
        if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
            (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
            (IDB3_VehicleSpd_flag > 10 and ttc < 2):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标ttc过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        gap = EnvmGenObjectList_aObject_2_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
        if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
            (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标time_gap过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 3:
        ttc = EnvmGenObjectList_aObject_3_Kinematic_fDistX / (
                EnvmGenObjectList_aObject_3_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
        IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
        if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
            (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
            (IDB3_VehicleSpd_flag > 10 and ttc < 2):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标ttc过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        gap = EnvmGenObjectList_aObject_3_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
        if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
             (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标time_gap过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 4:
        ttc = EnvmGenObjectList_aObject_4_Kinematic_fDistX / (EnvmGenObjectList_aObject_4_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
        IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
        if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
            (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
            (IDB3_VehicleSpd_flag > 10 and ttc < 2):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标ttc过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        gap = EnvmGenObjectList_aObject_4_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
        if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
            (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标time_gap过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 5:
        ttc = EnvmGenObjectList_aObject_5_Kinematic_fDistX / (
                EnvmGenObjectList_aObject_5_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
        IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
        if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
          (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
          (IDB3_VehicleSpd_flag > 10 and ttc < 2):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标ttc过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        gap = EnvmGenObjectList_aObject_5_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
        if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
            (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
            level1 = "紧急转向"
            level2 = "触发时刻"
            level3 = "与高亮目标time_gap过小"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    if (AccDisplayObj_CONTROL_ACCEL < -4.6 and IDB3_VehicleSpd / 3.6 <= 5) or \
        ((IDB3_VehicleSpd / 3.6 > 5 and IDB3_VehicleSpd / 3.6 <= 20) and AccDisplayObj_CONTROL_ACCEL < 0.066666667 * (IDB3_VehicleSpd / 3.6) - 4.933333333) or \
        (IDB3_VehicleSpd / 3.6 > 20 and AccDisplayObj_CONTROL_ACCEL < -3.6):
        dict = {}
        dict["vehicle_id"] = vechicle_id
        dict["start_time_str"] = start_time_str
        dict["scid"] = bagid
        dict["path"] = path
        level1 = "紧急转向"
        level2 = "触发时刻"
        level3 = "a_request过小"


        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    return dict_list
def get_scid_time(df_100ms_list):
    found_ICU2_Odometer=0.0
    found_IDB3_VehicleSpd=0.0
    found_ACU2_LongAccSensorValue=0.0
    found_ACU2_LatAccSensorValue=0.0
    found_ACU2_VehicleDynYawRate=0.0
    found_EPS1_SteerAngleSpd=0.0
    found_lane_curvature=0.0
    found_EPS1_TorsionBarTorque=0.0
    found_CS1_GearPositionReqSt=0
    for index, element in enumerate(df_100ms_list):
        start_time_str=element[0]
        path=element[1]
        nsecs=element[2]
        ADCS8_NPilot_SysState=element[15]
        ADCS8_NNPSysState=element[16]
        ADCS2_EPS_LDPState=element[25]
        BDCS1_TurnLightSW=element[26]
        ICU2_Odometer = element[17]
        IDB3_VehicleSpd = element[8]
        ACU2_LongAccSensorValue = element[9]
        ACU2_LatAccSensorValue = element[10]
        ACU2_VehicleDynYawRate = element[11]
        EPS1_SteerAngleSpd = element[13]
        lane_curvature = element[14]
        EPS1_TorsionBarTorque = element[18]
        CS1_GearPositionReqSt = element[19]

        if (ADCS8_NNPSysState==2 or ADCS8_NPilot_SysState==2 or ADCS2_EPS_LDPState==2) and (abs(ACU2_VehicleDynYawRate)>2) and (BDCS1_TurnLightSW==0) and \
            ((IDB3_VehicleSpd>=100 and abs(EPS1_SteerAngleSpd)>16)  or \
             (IDB3_VehicleSpd>=80 and IDB3_VehicleSpd<100 and abs(EPS1_SteerAngleSpd)>22) or \
             (IDB3_VehicleSpd>=60 and IDB3_VehicleSpd<80 and abs(EPS1_SteerAngleSpd)>25) or \
             (IDB3_VehicleSpd>=50 and IDB3_VehicleSpd<60 and abs(EPS1_SteerAngleSpd)>40) or\
             (IDB3_VehicleSpd>=40 and IDB3_VehicleSpd<50 and abs(EPS1_SteerAngleSpd)>50) or\
             (IDB3_VehicleSpd>30 and IDB3_VehicleSpd<40 and abs(EPS1_SteerAngleSpd)>60)
            ):
            found_index=index
            found_nsecs=nsecs
            found_ICU2_Odometer=ICU2_Odometer
            found_IDB3_VehicleSpd=IDB3_VehicleSpd
            found_ACU2_LongAccSensorValue=ACU2_LongAccSensorValue
            found_ACU2_LatAccSensorValue=ACU2_LatAccSensorValue
            found_ACU2_VehicleDynYawRate=ACU2_VehicleDynYawRate
            found_EPS1_SteerAngleSpd=EPS1_SteerAngleSpd
            found_lane_curvature=lane_curvature
            found_EPS1_TorsionBarTorque=EPS1_TorsionBarTorque
            found_CS1_GearPositionReqSt=CS1_GearPositionReqSt

            break;

    logging.info("found_index: " + str(found_index))
    dict_scid = {}
    dict_scid["scid_start_time_str"] = start_time_str
    dict_scid["ICU2_Odometer"] = found_ICU2_Odometer
    dict_scid["IDB3_VehicleSpd"] = found_IDB3_VehicleSpd
    dict_scid["ACU2_LongAccSensorValue"] = found_ACU2_LongAccSensorValue
    dict_scid["ACU2_LatAccSensorValue"] = found_ACU2_LatAccSensorValue
    dict_scid["ACU2_VehicleDynYawRate"] = found_ACU2_VehicleDynYawRate
    dict_scid["EPS1_SteerAngleSpd"] = found_EPS1_SteerAngleSpd
    dict_scid["lane_curvature"] = found_lane_curvature
    dict_scid["EPS1_TorsionBarTorque"] = found_EPS1_TorsionBarTorque
    dict_scid["CS1_GearPositionReqSt"] = found_CS1_GearPositionReqSt
    return dict_scid
def get_can_20ms_list(df_can_20ms_list,nsecs):
    # 找到最接近目标值的行数据
    closest_data = min(df_can_20ms_list, key=lambda x: abs(x[2] - nsecs))

    # 打印结果
    return  closest_data
def get_dict(vechicle_id,start_time_str,bagid,path,scid_dict,level1,level2,level3):
    dict = {}
    dict["vehicle_id"] = vechicle_id
    dict["start_time_str"] = start_time_str
    dict["scid"] = bagid
    dict["path"] = path
    dict["level1"] = level1
    dict["level2"] = level2
    dict["level3"] = level3
    day = start_time_str[0:4] + start_time_str[5:7] + start_time_str[8:10]
    month = start_time_str[0:4] + start_time_str[5:7]
    dict["day"] = day
    dict["month"] = month
    dict["scid_start_time_str"] = scid_dict["scid_start_time_str"]
    dict["icu2_odometer"] = scid_dict["ICU2_Odometer"]
    dict["idb3_vehiclespd"] = scid_dict["IDB3_VehicleSpd"]
    dict["acu2_longaccsensorvalue"] = scid_dict["ACU2_LongAccSensorValue"]
    dict["acu2_lataccsensorvalue"] = scid_dict["ACU2_LatAccSensorValue"]
    dict["acu2_vehicledynyawrate"] = scid_dict["ACU2_VehicleDynYawRate"]
    dict["eps1_steeranglespd"] = scid_dict["EPS1_SteerAngleSpd"]
    dict["lane_curvature"] = scid_dict["lane_curvature"]
    dict["eps1_torsionbartorque"] = scid_dict["EPS1_TorsionBarTorque"]
    dict["cs1_gearpositionreqst"] = scid_dict["CS1_GearPositionReqSt"]
    dict["lane_curvature"] = scid_dict["lane_curvature"]

    uid_string = vechicle_id + start_time_str + bagid + level1 + level2 + level3
    uid = str(uuid.uuid3(uuid.NAMESPACE_DNS, uid_string))
    dict["uid"] = uid
    return dict
def get_dict_list(dict):
    data_list=[]
    data_list.append(dict['vehicle_id'])
    data_list.append(dict['start_time_str'])
    data_list.append(dict['scid'])
    data_list.append(dict['path'])
    data_list.append(dict['level1'])
    data_list.append(dict['level2'])
    data_list.append(dict['level3'])
    data_list.append(dict['day'])
    data_list.append(dict['month'])
    data_list.append(dict["scid_start_time_str"])
    data_list.append(dict['icu2_odometer'])
    data_list.append(dict['idb3_vehiclespd'])
    data_list.append(dict['acu2_longaccsensorvalue'])
    data_list.append(dict['acu2_lataccsensorvalue'])
    data_list.append(dict['acu2_vehicledynyawrate'])
    data_list.append(dict['eps1_steeranglespd'])
    data_list.append(dict['lane_curvature'])
    data_list.append(dict['eps1_torsionbartorque'])
    data_list.append(dict['cs1_gearpositionreqst'])
    data_list.append(dict['uid'])
    data_list.append(dict['day'])
    return data_list
def add_to_mysql(json_str):
    # 配置数据库连接信息
    db_config = {
        'host': 'mysql-d8beb8b0655b-public.rds.volces.com',
        'user': 'user01',
        'password': 'password123!#',
        'database': 'bi_test'
    }
    # 创建数据库连接
    conn = mysql.connector.connect(**db_config)
    cursor = conn.cursor()

    # 假设你有一个名为 'your_table' 的表，包含 'column1', 'column2', 'column3' 等字段
    table_name = 'trigger_sc_ep40_tda4'

    # 假设你有一个数据字典，包含要插入的数据
    data_to_insert = json.loads(json_str)

    # 构建 SQL 插入语句
    columns = ', '.join(data_to_insert.keys())
    values = ', '.join(['%s'] * len(data_to_insert))
    sql_insert = f"replace into {table_name} ({columns}) VALUES ({values})"

    # 执行插入操作
    cursor.execute(sql_insert, list(data_to_insert.values()))

    # 提交更改
    conn.commit()
def get_timestamp(time_string):
    # 转换为时间元组
    time_tuple = time.strptime(time_string, "%Y-%m-%d %H:%M:%S")
    # 转换为时间戳
    timestamp = str(int(time.mktime(time_tuple)*1000))
    return timestamp
def get_emergency_steering_label(df_can_100ms_save_path,df_can_20ms_save_path, vechicle_id, daystr, hourstr, bagid, uuids, file_type):
    try:
        df_can_100ms = pd.read_pickle(df_can_100ms_save_path)
    except Exception as e:
        print('data report read error, ', str(e))

    try:
        df_can_20ms = pd.read_pickle(df_can_20ms_save_path)
    except Exception as e:
        print('data report read error, ', str(e))

    df_100ms_list = df_can_100ms[
        ['start_time_str', 'path', 'nsecs', 'VLCCDHypotheses_Hypothesis_0_fTTC', 'VLCCDHypotheses_Hypothesis_0_fDistX',
         'VLCCDHypotheses_Hypothesis_0_fDistY',
         'VLCCDHypotheses_Hypothesis_0_fVrelX', 'VLCCDHypotheses_Hypothesis_0_fVrelY', 'IDB3_VehicleSpd',
         'ACU2_LongAccSensorValue', 'ACU2_LatAccSensorValue',
         'ACU2_VehicleDynYawRate', 'IDB1_BrakePedalApplied', 'EPS1_SteerAngleSpd',
         'CamLaneData_CourseInfo_1_CourseInfoSegNear_f_C0',
         'ADCS8_NPilot_SysState', 'ADCS8_NNPSysState', 'ICU2_Odometer', 'EPS1_TorsionBarTorque', 'CS1_GearPositionReqSt','IDB5_AEBactive',
         'ADCS2_AEB_DBSLevel','ADCS8_ACCState','VLCCDHypotheses_Hypothesis_0_eEBAObjectClass','AccDisplayObj_CONTROL_ACCEL','ADCS2_EPS_LDPState','BDCS1_TurnLightSW'
         ]].values.tolist()
    df_can_20ms_list = df_can_20ms[
        ['start_time_str', 'path', 'VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID',
         'EnvmGenObjectList_aObject_0_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_0_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_0_Kinematic_fDistX', 'EnvmGenObjectList_aObject_0_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_0_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_0_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_1_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_1_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_1_Kinematic_fDistX', 'EnvmGenObjectList_aObject_1_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_1_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_1_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_2_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_2_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_2_Kinematic_fDistX', 'EnvmGenObjectList_aObject_2_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_2_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_2_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_3_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_3_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_3_Kinematic_fDistX', 'EnvmGenObjectList_aObject_3_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_3_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_3_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_4_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_4_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_4_Kinematic_fDistX', 'EnvmGenObjectList_aObject_4_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_4_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_4_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_5_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_5_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_5_Kinematic_fDistX', 'EnvmGenObjectList_aObject_5_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_5_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_5_Kinematic_fVabsY'
         ]].values.tolist()

    #获取触发时状态：
    dict_list=[]
    scid_dict = get_scid_time(df_100ms_list)
    found_start_time_str=""
    found_path=""
    found_index= -9999
    found_nsecs=0
    found_lane_curvature=0.0
    found_VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID=0.0
    found_VLCCDHypotheses_Hypothesis_0_fVrelX=0.0
    found_VLCCDHypotheses_Hypothesis_0_fVrelY=0.0
    found_IDB3_VehicleSpd=0.0
    found_VLCCDHypotheses_Hypothesis_0_eEBAObjectClass=0
    for index, element in enumerate(df_100ms_list):
        start_time_str=element[0]
        path=element[1]
        nsecs=element[2]
        ADCS8_NPilot_SysState=element[15]
        ADCS8_NNPSysState=element[16]
        ADCS2_EPS_LDPState=element[25]
        ACU2_VehicleDynYawRate=element[11]
        BDCS1_TurnLightSW=element[26]
        IDB3_VehicleSpd=element[8]
        EPS1_SteerAngleSpd=element[13]
        lane_curvature = element[14]
        VLCCDHypotheses_Hypothesis_0_fVrelX=element[6]
        VLCCDHypotheses_Hypothesis_0_fVrelY = element[5]
        VLCCDHypotheses_Hypothesis_0_eEBAObjectClass= element[23]


        if (ADCS8_NNPSysState==2 or ADCS8_NPilot_SysState==2 or ADCS2_EPS_LDPState==2) and (abs(ACU2_VehicleDynYawRate)>2) and (BDCS1_TurnLightSW==0) and \
            ((IDB3_VehicleSpd>=100 and abs(EPS1_SteerAngleSpd)>16)  or \
             (IDB3_VehicleSpd>=80 and IDB3_VehicleSpd<100 and abs(EPS1_SteerAngleSpd)>22) or \
             (IDB3_VehicleSpd>=60 and IDB3_VehicleSpd<80 and abs(EPS1_SteerAngleSpd)>25) or \
             (IDB3_VehicleSpd>=50 and IDB3_VehicleSpd<60 and abs(EPS1_SteerAngleSpd)>40) or\
             (IDB3_VehicleSpd>=40 and IDB3_VehicleSpd<50 and abs(EPS1_SteerAngleSpd)>50) or\
             (IDB3_VehicleSpd>30 and IDB3_VehicleSpd<40 and abs(EPS1_SteerAngleSpd)>60)
            ):
            found_index=index
            found_nsecs=nsecs
            found_start_time_str=start_time_str
            found_lane_curvature=lane_curvature
            found_VLCCDHypotheses_Hypothesis_0_fVrelX=VLCCDHypotheses_Hypothesis_0_fVrelX
            found_VLCCDHypotheses_Hypothesis_0_fVrelY=VLCCDHypotheses_Hypothesis_0_fVrelY
            found_IDB3_VehicleSpd=IDB3_VehicleSpd
            found_VLCCDHypotheses_Hypothesis_0_eEBAObjectClass=VLCCDHypotheses_Hypothesis_0_eEBAObjectClass

            break;
    hour=found_start_time_str[11:13]
    if hour.startswith("0"):
        hour=hour[1:2]
    if (int(hour)>=8 and int(hour)<=20):
        level1="紧急转向"
        level2="环境"
        level3="白天"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    if (int(hour)>20 or int(hour)<8):
        level1="紧急转向"
        level2="环境"
        level3="晚上"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)

    if found_lane_curvature>=0.05:
        level1="紧急转向"
        level2="道路场景"
        level3="大曲率弯道"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)

    if found_lane_curvature==0.0:
        level1="紧急转向"
        level2="道路场景"
        level3="自车道线丢失"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)


    list_20ms=get_can_20ms_list(df_can_20ms_list,found_nsecs)
    VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID=list_20ms[2]
    EnvmGenObjectList_aObject_1_Kinematic_fAabsX=list_20ms[9]
    EnvmGenObjectList_aObject_2_Kinematic_fAabsX = list_20ms[15]
    EnvmGenObjectList_aObject_3_Kinematic_fAabsX = list_20ms[21]
    EnvmGenObjectList_aObject_4_Kinematic_fAabsX = list_20ms[27]
    EnvmGenObjectList_aObject_5_Kinematic_fAabsX = list_20ms[33]

    if VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID==1:
        if EnvmGenObjectList_aObject_1_Kinematic_fAabsX<= -3:
            level1 = "紧急转向"
            level2 = "障碍物状态"
            level3 = "前方车辆急减速"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID==2:
        if EnvmGenObjectList_aObject_2_Kinematic_fAabsX<= -3:
            level1 = "紧急转向"
            level2 = "障碍物状态"
            level3 = "前方车辆急减速"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID==3:
        if EnvmGenObjectList_aObject_3_Kinematic_fAabsX<= -3:
            level1 = "紧急转向"
            level2 = "障碍物状态"
            level3 = "前方车辆急减速"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID==4:
        if EnvmGenObjectList_aObject_4_Kinematic_fAabsX<= -3:
            level1 = "紧急转向"
            level2 = "障碍物状态"
            level3 = "前方车辆急减速"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID==5:
        if EnvmGenObjectList_aObject_5_Kinematic_fAabsX<= -3:
            level1 = "紧急转向"
            level2 = "障碍物状态"
            level3 = "前方车辆急减速"
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
    if abs(found_VLCCDHypotheses_Hypothesis_0_fVrelX)==0 and abs(found_VLCCDHypotheses_Hypothesis_0_fVrelY)==0:
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "前方静止目标"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    elif abs(found_VLCCDHypotheses_Hypothesis_0_fVrelX)>1 and (found_IDB3_VehicleSpd/3.6 + found_VLCCDHypotheses_Hypothesis_0_fVrelX)<=1:
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "横穿"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    elif abs(found_VLCCDHypotheses_Hypothesis_0_fVrelX)>1 and (found_IDB3_VehicleSpd/3.6 + found_VLCCDHypotheses_Hypothesis_0_fVrelX)>1:
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "斜穿"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    elif  (found_IDB3_VehicleSpd/3.6 + found_VLCCDHypotheses_Hypothesis_0_fVrelX)>-2:
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "纵向OnComing"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    else:
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "纵向跟随"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)

    if(found_VLCCDHypotheses_Hypothesis_0_eEBAObjectClass==1):
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "行人"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    elif (found_VLCCDHypotheses_Hypothesis_0_eEBAObjectClass==2):
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "车辆"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    elif (found_VLCCDHypotheses_Hypothesis_0_eEBAObjectClass==4):
        level1 = "紧急转向"
        level2 = "障碍物状态"
        level3 = "两轮车"
        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
        data_list = get_dict_list(dict)
        dict_list.append(data_list)
    dict_list=get_ttc(df_can_20ms_list, df_100ms_list, found_index, found_nsecs, vechicle_id, bagid, scid_dict, dict_list)
    add_to_bytehouse(dict_list)


















